//
//  YinDaoViewController.m
//  Com.wusi.ruijin
//
//  Created by hackapple on 15-3-27.
//  Copyright (c) 2015年 admin. All rights reserved.
//

#import "YinDaoViewController.h"

@interface YinDaoViewController ()<UIScrollViewDelegate>
{
    UIPageControl *_myPageControl;
}
@end

@implementation YinDaoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self drawView];
}

-(void)drawView{
    NSArray *imageAry_480 = @[@"1-960",@"2-960",@"3-960",@"4-960",@"5-960"];
    NSArray *imageAry_568 = @[@"1-1136",@"2-1136",@"3-1136",@"4-1136",@"5-1136"];

    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, -20, KScreenWidth, KScreenHeight + 20)];
    _scrollView.bounces = NO;
    _scrollView.delegate = self;
    [_scrollView setPagingEnabled:YES];
    
    for (int i = 0 ; i < imageAry_480.count; i++) {
        UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(KScreenWidth * i, 0, KScreenWidth, KScreenHeight)];
        imageView.backgroundColor = [UIColor redColor];
    
        if(KScreenWidth == 480){
            [imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_new", [imageAry_480 objectAtIndex:i]]]];
        }else{
            [imageView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_new",[imageAry_568 objectAtIndex:i]]]];

        }
        [_scrollView addSubview:imageView];
        if (i == imageAry_480.count - 1) {
             UIButton *beginButton = [[UIButton alloc]initWithFrame:CGRectMake(0 ,0, KScreenWidth, KScreenHeight)];
            
//            UIButton *beginButton = [[UIButton alloc]initWithFrame:CGRectMake(80 * _kscW, KreenHight - 140 * _kscH, 160 * _kscW, 40 * _kscH)];
//            beginButton.layer.cornerRadius = 5;
//            beginButton.layer.borderColor = [[UIColor whiteColor]CGColor];
//            beginButton.layer.borderWidth = 1;
//            [beginButton setTitle:@"开始体验之旅" forState:UIControlStateNormal];
            [beginButton addTarget:self action:@selector(beginClicked:) forControlEvents:UIControlEventTouchUpInside];
            imageView.userInteractionEnabled = YES;
            [imageView addSubview:beginButton];
        }
    }
    
    [self.view addSubview:_scrollView];
    _scrollView.contentSize = CGSizeMake(KScreenWidth * imageAry_480.count, KScreenHeight );
    
    
    _myPageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, KScreenHeight - 100 * _kscH, KScreenWidth, 30 * _kscH)];
    _myPageControl.numberOfPages = imageAry_480.count;

    
    _myPageControl.currentPage = 0;
    
    _myPageControl.enabled = NO;

    [self.view addSubview:_myPageControl];
}

-(void)beginClicked:(id)sender{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    int page = scrollView.contentOffset.x/KScreenWidth;
    [_myPageControl setCurrentPage:page];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
